package userlimitRequest

import (
	"arabApi/app/api/requests"
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type MenuAdd struct {
	ID    int64  `gorm:"column:id" db:"id" json:"id" form:"id"`
	PId   int64  `gorm:"column:p_id" db:"p_id" json:"p_id" form:"p_id"  `                 //  父级id
	Index string `gorm:"column:index" db:"index" json:"index" form:"index" valid:"index"` //  index
	Title string `gorm:"column:title" db:"title" json:"title" form:"title" valid:"title"` //  标题
	Type  int64  `gorm:"column:type" db:"type" json:"type" form:"type" valid:"type"`      //  1 菜单 2 链接
	Order int64  `gorm:"column:order" db:"order" json:"order" form:"order" valid:"order"` //  1 菜单 2 链接
}

func CheckMenu(data interface{}, c *gin.Context) string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"index": []string{"required"},
		"title": []string{"required"},
		"type":  []string{"required"},
		"order": []string{"required"},
	}
	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"name": []string{
			"required:菜单名称不能为空",
		},
		"index": []string{
			"required:index不能为空",
		},
		"title": []string{
			"required:title不能为空",
		},
		"type": []string{
			"required:类型不能为空",
		},
		"order": []string{
			"required:类型不能为空",
		},
	}

	errs := requests.Validate1(data, rules, messages)
	return requests.GetOneErr(errs)
}
